package com.csinc.generate.core.util;

import java.util.Set;
import java.util.TreeSet;

/**
 * Create By 郭金宝 on 2018/7/25.<br>
 */
public class FreeMakerUtil {

    public static String upFirst(String str) {
        if (str == null || str.trim().equals("")) return str;
        return str.substring(0, 1).toUpperCase() + str.substring(1);
    }

    public static String firstLower(String str) {
        if (str == null || str.trim().equals("")) return str;
        return str.substring(0, 1).toLowerCase() + str.substring(1);
    }

    public static String lowers(String str) {
        if (str == null || str.trim().equals("")) return str;
        return str.toLowerCase();
    }

    public static boolean underLine(String str) {
        if (str == null || str.trim().equals("")) return false;
        int t = str.indexOf("_");
        if (t > -1) {
            return true;
        }
        return false;
    }

    public static Set<String> imports(Set<String> importList) {
        Set<String> set = new TreeSet<String>();
        for (String str : importList) {
            if (!str.startsWith("java.lang")) {
                set.add(str);
            }
        }
        return set;
    }

    public static String javaName(String name) {
        int t = name.indexOf("_");
        String str = name;
        if (t > -1) {
            String prefix = name.substring(0, t);
            if (t >= name.length()-1) {
                return prefix;
            }
            String suffix = name.substring(t+1);
            str = prefix + suffix.substring(0, 1).toUpperCase() + suffix.substring(1);
        }
        t = name.indexOf("_");
        if (t > -1) {
            return javaName(str);
        }
        return name.substring(0,1).toLowerCase() + name.substring(1);
    }

    public static String javaName(String table, String frefix) {
        if (frefix == null || frefix.trim().equals("")) {
            String t = table.toLowerCase();
            return javaName(t);
        } else {
            int t = table.toLowerCase().indexOf(frefix.toLowerCase());
            if (t == 0) {
                String ls = table.toLowerCase().substring(t + frefix.length());
                return javaName(ls);
            } else {
                return javaName(table);
            }
        }
    }

    public static String beanName(String table) {
        String str = javaName(table.toLowerCase());
        return str.substring(0, 1).toUpperCase() + str.substring(1);
    }

    public static String lower(String name) {
        return name.substring(0, 1).toLowerCase() + name.substring(1);
    }

    public static String firstUpper(String name) {
        return name.substring(0, 1).toUpperCase() + name.substring(1);
    }


    public static boolean isMysql() {
        return true;
    }

    public static boolean isOracle() {
        return false;
    }


    public static void main(String[] args) {
        Integer id = 12;
        if (id.getClass().isPrimitive() || (Number.class.isAssignableFrom(id.getClass()))) {
            System.out.println("true");
        } else {
            System.out.println("false");
        }
    }
}

